/*
* $Id: DeletePointWizard.java 272 2011-02-21 05:37:35Z volok-aleksej@yandex.ru $
*
* Copyright 2008-2011 by Volokitin Alexey
* All rights reserved
*
*/
package apiary.component.journal;


import apiary.Apiary;
import apiary.db.managers.DBManager;
import apiary.ui.BackScreen;
import apiary.common.FormHelper;
import apiary.ui.journal.ChooseForm;
import apiary.ui.journal.ChooseForm.ChooseValue;
import apiary.ui.journal.DeleteForm;
import apiary.ui.journal.WizardScreen;

/**
 * Wizard of deleting point
 * @author lexus
 */
public class DeletePointWizard extends Wizard
{
    /**
     * Constructror
     */
    public DeletePointWizard() {
        super(null);
        Init();
    }

    /**
     * Constructror
     * @param parentForm Form where it want to move when pressing Back.
     * This form used only on first form of wizard
     */
    public DeletePointWizard(BackScreen parentForm) {
        super(null);
        Init();
        setCancelForm(parentForm);
    }

    /**
     * Saves result of wizard
     */
    public void save() {
        ChooseValue value = (ChooseValue) getData(new Integer(1));
        DBManager.getInstance().deletePoint(value.id);
    }

    /**
     * Calls before to show next form of wizard
     * @param nextForm next form of wizard
     */
    public void next(BackScreen nextForm) {
        WizardScreen screen = (WizardScreen) nextForm;
        if(screen.getIdForm().intValue() == 2) {
            DeleteForm deleteForm = (DeleteForm) nextForm;
            ChooseValue value = (ChooseValue) getData(new Integer(1));
            deleteForm.setName(value.value);
        }
    }

    /**
     * @deprecated not uses always return true
     */
    public boolean isOk(Integer idForm, Object dataForm) {
        return true;
    }

    /**
     * Initialize Wizard
     */
    private void Init() {
        Apiary apiary = Apiary.getInstance();
        Integer idChoose = new Integer(1);
        firstForm = new ChooseForm(apiary.getLocaleString("ChoosePoint"), idChoose, this, true);
        FormHelper.fillPointList((ChooseForm) firstForm);
        Integer idDelete = new Integer(2);
        DeleteForm deleteForm = new DeleteForm(apiary.getLocaleString("DeletePoint"), idDelete, this);
        deleteForm.setBackScreen(firstForm);
        formsNext.put(idChoose, deleteForm);
    }
}
